Transistors are basic building elements in integrated circuits. In recent development of the integrated circuits, transistors adopt metal gates, which are typically formed in the form of replacement gates. The formation of the replacement gates typically involves forming dummy gate stacks, forming gate spacers on sidewalls of the dummy gate stacks, removing the dummy gate stacks to form openings between the gate spacers, depositing gate dielectric layers and metal layers into the openings, and then performing Chemical Mechanical Polish (CMP) to remove excess portions of the gate dielectric layers and the metal layers. The remaining portions of the gate dielectric layers and the metal layers are replacement gates. There are typically multiple sub-layers in the replacement gates. With the increasing down-scaling of integrated circuits, the widths of the replacement gates become increasingly smaller, making it more difficult to accommodate the multiple sub-layers.